package com.vgooo.client.ui;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SlidingDrawer;

public class MSlidingDrawer extends SlidingDrawer{
	
    private int mTouchableId = 0; 
    private int mPointer = 0;


	public int getmPointer() {
		return mPointer;
	}

	public void setmPointer(int mPointer) {
		this.mPointer = mPointer;
	}

	public MSlidingDrawer(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public MSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public int getmTouchableId() {
		return mTouchableId;
	}

	public void setmTouchableId(int mTouchableId) {
		this.mTouchableId = mTouchableId;
	}


	@Override
	public void lock() {
		// TODO Auto-generated method stub
		super.lock();
	}

    public Rect getRectOnScreen(View view) {  
        Rect rect = new Rect();  
        int[] location = new int[2];  
        View parent = view;  
        if (view.getParent() instanceof View) {  
            parent = (View) view.getParent();  
        }  
        parent.getLocationOnScreen(location);  
        view.getHitRect(rect);  
        rect.offset(location[0], location[1]);  
        return rect;  
    }  
    

	public boolean onInterceptTouchEvent(MotionEvent event) {  
 
        int[] location = new int[2];  
        int x = (int) event.getX();  
        int y = (int) event.getY();  
        this.getLocationOnScreen(location);  
        x += location[0];  
        y += location[1];  

        View view = findViewById(mTouchableId);  
        Rect rect = getRectOnScreen(view);  
        if (rect.contains(x, y)) {  
  
            if(MotionEvent.ACTION_DOWN==event.getAction()){  
                 view.dispatchTouchEvent(event);  
            }     
            return false;  
        }  
        return super.onInterceptTouchEvent(event);  
    }
}
